#include "widget.h"
#include "ui_widget.h"
#include <QDebug>

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
}

Widget::~Widget()
{
    delete ui;
}


void Widget::on_pushButton_clicked()
{
    // 1. 先获取到这两个输入框之间的时间
    QDateTime timeold = ui->dateTimeEdit_old->dateTime();
    QDateTime timenew = ui->dateTimeEdit_new->dateTime();
    qDebug() << timeold << timenew;
    // 2. 计算日期差值
    // int days = timeold.daysTo(timenew);
    int seconds = timeold.secsTo(timenew);

    // 3. 把描述换算成小时
    int hours = (seconds / 3600) % 24;
    int days = (seconds / 3600) / 24;

    // 4. 把计算结果放到 label
    QString text = QString("距离上次见面已经：") + QString::number(days) +
               QString(" 天 零") + QString::number(hours) + QString(" 个小时");
    ui->label->setText(text);
}
